cmake_minimum_required(VERSION 3.15)

project(path_planning_sim)

set(CMAKE_CXX_STANDARD                 14)
set(CMAKE_EXPORT_COMPILE_COMMANDS      ON)
set(CMAKE_POSITION_INDEPENDENT_CODE    ON)
set(INNER_DIR                          ${CMAKE_CURRENT_SOURCE_DIR}/inner_libs)
set(INNER_INCLUDE_DIR                  ${INNER_DIR}/usr/include)
set(INNER_LIB_DIR                      ${INNER_DIR}/usr/lib)
set(INNER_BIN_DIR                      ${INNER_DIR}/usr/bin)
set(INNER_CONFIG_DIR                   ${INNER_DIR}/usr/cfg)
set(INNER_PKGCONFIG_DIR                ${INNER_LIB_DIR}/pkgconfig)
set(INNER_CMAKE_DIR                    ${INNER_LIB_DIR}/cmake)


add_subdirectory(navigator)
add_subdirectory(simulation)
add_subdirectory(common)
add_subdirectory(csv)

# 添加源文件
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} SRC)

# 搜索头文件
include_directories(
    ${CMAKE_CURRENT_SOURCE_DIR}
    ${INNER_INCLUDE_DIR}
)

# 链接库的搜索路径
# 必须在 target_link_libraries 前面
link_directories(
    ${INNER_LIB_DIR}
    ${OpenCV_LIBRARY_DIRS}
)

add_executable(${PROJECT_NAME} ${SRC})

# 添加依赖库
# ${PROJECT_NAME} 依赖于 a_star
add_dependencies(${PROJECT_NAME} navigator)
add_dependencies(${PROJECT_NAME} simulation)
add_dependencies(${PROJECT_NAME} csv_ops)
add_dependencies(${PROJECT_NAME} inner_common)

# 编译链接的库
target_link_libraries(${PROJECT_NAME}
    pthread
    navigator
    csv_ops
    simulation
    inner_common
    ${OpenCV_LIBS}
)

# 从build/复制bin文件到inner_libs/usr/bin
install(TARGETS ${PROJECT_NAME}
    RUNTIME DESTINATION ${INNER_BIN_DIR}
    LIBRARY DESTINATION ${INNER_LIB_DIR}
    ARCHIVE DESTINATION ${INNER_LIB_DIR}
)
